load("//xla:xla.default.bzl", "xla_cc_test")
load("//xla/tsl:tsl.bzl", "internal_visibility")
load("//xla/tsl/platform:rules_cc.bzl", "cc_library")

package(
    # copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
    default_visibility = internal_visibility(["//xla:internal"]),
    licenses = ["notice"],
)

package_group(
    name = "friends",
    includes = [
        "//xla:friends",
        "//xla:internal",
    ],
    packages = [
        "//tensorflow/core/tfrt/ifrt/...",
        "//third_party/australis/...",
        "//third_party/gxlang/...",
        "//third_party/openxla_pjrt_plugin/...",
        "//third_party/py/jax/...",
        "//third_party/py/torch_tpu/...",
    ],
)

cc_library(
    name = "pjrt_c_api_client",
    srcs = [
        "pjrt_c_api_client.cc",
        "pjrt_c_api_phase_compiler.cc",
    ],
    hdrs = [
        "pjrt_c_api_client.h",
        "pjrt_c_api_phase_compiler.h",
    ],
    visibility = internal_visibility([":friends"]),
    deps = [
        "//xla:future",
        "//xla:literal",
        "//xla:shape_util",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla:xla_proto_cc",
        "//xla/ffi:execution_context",
        "//xla/hlo/builder:xla_computation",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/translate/mhlo_to_hlo:mlir_hlo_to_hlo",
        "//xla/mlir_hlo:mhlo_passes",
        "//xla/pjrt:mlir_to_hlo",
        "//xla/pjrt:partial_program_utils",
        "//xla/pjrt:pjrt_api",
        "//xla/pjrt:pjrt_client",
        "//xla/pjrt:pjrt_common",
        "//xla/pjrt:pjrt_compiler",
        "//xla/pjrt:pjrt_device_description",
        "//xla/pjrt:pjrt_device_dimensions",
        "//xla/pjrt:pjrt_executable",
        "//xla/pjrt:pjrt_layout",
        "//xla/pjrt:string_utils",
        "//xla/pjrt/c:pjrt_c_api_ffi_extension_hdrs",
        "//xla/pjrt/c:pjrt_c_api_hdrs",
        "//xla/pjrt/c:pjrt_c_api_helpers",
        "//xla/pjrt/c:pjrt_c_api_layouts_extension_hdrs",
        "//xla/pjrt/c:pjrt_c_api_memory_descriptions_extension_hdrs",
        "//xla/pjrt/c:pjrt_c_api_phase_compile_extension_hdrs",
        "//xla/pjrt/c:pjrt_c_api_profiler_extension_hdrs",
        "//xla/pjrt/c:pjrt_c_api_stream_extension_hdrs",
        "//xla/pjrt/c:pjrt_c_api_tpu_topology_extension_hdrs",
        "//xla/pjrt/distributed:key_value_store_interface",
        "//xla/pjrt/extensions/cross_host_transfers:pjrt_c_api_cross_host_transfer_extension",
        "//xla/pjrt/extensions/executable_metadata:executable_metadata_extension",
        "//xla/pjrt/extensions/host_allocator:host_allocator_extension",
        "//xla/pjrt/extensions/host_allocator:host_allocator_interface_impl",
        "//xla/pjrt/proto:compile_options_proto_cc",
        "//xla/pjrt/proto:topology_description_proto_cc",
        "//xla/service:computation_placer_hdr",
        "//xla/service:hlo_cost_analysis",
        "//xla/service:hlo_proto_cc",
        "//xla/tsl/framework:allocator",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:statusor",
        "//xla/tsl/protobuf:coordination_service_proto_cc",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/cleanup",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/functional:any_invocable",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/types:span",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:Support",
        "@tsl//tsl/platform:casts",
        "@tsl//tsl/platform:fingerprint",
    ],
)

xla_cc_test(
    name = "pjrt_c_api_client_test",
    srcs = ["pjrt_c_api_client_test.cc"],
    tags = [
        "nomsan",
    ],
    deps = [
        ":pjrt_c_api_client",
        "//xla:future",
        "//xla:literal",
        "//xla:literal_util",
        "//xla:shape_util",
        "//xla:types",
        "//xla/backends/cpu:alignment",
        "//xla/ffi",
        "//xla/ffi:ffi_api",
        "//xla/hlo/builder:xla_builder",
        "//xla/hlo/builder:xla_computation",
        "//xla/hlo/parser:hlo_parser",
        "//xla/pjrt:mlir_to_hlo",
        "//xla/pjrt:pjrt_api",
        "//xla/pjrt:pjrt_client",
        "//xla/pjrt:pjrt_compiler",
        "//xla/pjrt:pjrt_device_description",
        "//xla/pjrt:pjrt_executable",
        "//xla/pjrt/c:pjrt_c_api_cpu_internal",
        "//xla/pjrt/c:pjrt_c_api_hdrs",
        "//xla/service:computation_placer_hdr",
        "//xla/tests:literal_test_util",
        "//xla/tsl/lib/core:status_test_util",
        "//xla/tsl/platform:env",
        "//xla/tsl/platform:statusor",
        "//xla/tsl/platform:test",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/types:span",
        "@com_google_googletest//:gtest_main",
        "@llvm-project//mlir:IR",
        "@stablehlo//:version",
    ],
)

xla_cc_test(
    name = "pjrt_c_api_client_tpu_test",
    srcs = ["pjrt_c_api_client_tpu_test.cc"],
    tags = ["no_oss"],
    deps = [
        ":pjrt_c_api_client",
        "//xla/pjrt:pjrt_common",
        "//xla/pjrt:pjrt_compiler",
        "//xla/pjrt:pjrt_device_dimensions",
        "//xla/pjrt/plugin/xla_tpu:xla_tpu_pjrt_client",  # buildcleaner: keep
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@com_google_googletest//:gtest_main",
    ],
)
